<?php
header("content-type:text/html;charset=utf-8");
$conn= new mysqli("localhost", "root", "");


function _select_data($conn,$sql){
    $ret = mysqli_query($conn,$sql) or die('SQL语句有错误，错误信息：'.mysqli_error($conn));
    return $ret;
}
    $var=rand(1,100);

    $sql_wxdd_status="select tag4 from wyl.wxdd where id=1";
    $result_wxdd_status = _select_data($conn,$sql_wxdd_status);
    $data_wxdd_status=mysqli_fetch_assoc($result_wxdd_status);
    $tag = $data_wxdd_status['tag4'];
    var_dump($tag);



    sleep(10);
    //程序停止运行60秒后，查询开关状态，和之前的状态进行比对，如果相同就进行自动复位
    $sql_wxdd="select tag4 from wyl.wxdd where id=1";
    $result_wxdd = _select_data($conn,$sql_wxdd);
    $data_wxdd=mysqli_fetch_assoc($result_wxdd);
    $tag1 = $data_wxdd['tag4'];
    var_dump($tag1);
    if ($tag1 == $tag) {
        if ($tag == '1') {
            $select_sql="update wyl.wxdd set tag4=2";   
            $select_res=_select_data($conn,$select_sql);
            echo '我来1了';
        } else {
            $select_sql="update wyl.wxdd set tag4=1";   
            $select_res=_select_data($conn,$select_sql);
            echo '我来2了';
        }
        
        $select_sql="update wyl.wxcc set tag2=$var";
        $select_res=_select_data($conn,$select_sql);
        echo '我来fuwei了';
        exit;
    }
    echo '手动复位了';